var utils = {};
//公共处理方法
utils.install = function(Vue, option) {
	//页面跳转
	Vue.prototype.jump = function(path) {
		uni.navigateTo({
			url: path
		})
	};
	//返回
	Vue.prototype.back = function(obj) {
		uni.navigateBack(obj);
	};
	//跳转传参
	Vue.prototype.togo = function(url, data) {
		url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
		uni.navigateTo({
			url
		})
	};
	function param(data) {
		let url = ''
		for (var k in data) {
			let value = data[k] !== undefined ? data[k] : ''
			url += '&' + k + '=' + encodeURIComponent(value)
		}
		return url ? url.substring(1) : ''
	};
	//获取文件API
	Vue.prototype.getFileApi = function() {
		return 'http://localhost:8089/api/file/'
	};
	//日期处理
	Vue.prototype.dateFormat = function(time, type) {
		var weekDayString = ''
		var date = new Date(time)
		var year = date.getFullYear()
		var month = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1
		var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
		var hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours()
		var minutes = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()
		var seconds = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
		var weekDay = date.getDay()
		if (weekDay == 1) {
			weekDayString = "星期一";
		} else if (weekDay == 2) {
			weekDayString = "星期二";
		} else if (weekDay == 3) {
			weekDayString = "星期三";
		} else if (weekDay == 4) {
			weekDayString = "星期四";
		} else if (weekDay == 5) {
			weekDayString = "星期五";
		} else if (weekDay == 6) {
			weekDayString = "星期六";
		} else if (weekDay == 7) {
			weekDayString = "星期日";
		}
		if (type == 1) {
			return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds
		} else if (type == 2) {
			return year + '年' + month + '月' + day + '日   ' + weekDayString
		}
	};
};

export default utils;
